package bishi.xiaohongshu;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Classname Main1
 * @Description TODO
 * @Date 2021/9/18 11:08
 * @Created by ASUS
 */
public class Main1 {
    /*
3 6
BBBBBB
BRBOBB
BBBBOB
6
Turn right
Forward 3
Turn left
Forward 2
Turn left
Forward 1
     */
    static String[] FACE_TO = new String[]{"上", "下", "左", "右"};

    static String changeDirection(String cur, String op) {
        switch (cur) {
            case "上": {
                switch (op) {
                    case "Turn right": {
                        return "右";
                    }
                    case "Turn left": {
                        return "左";
                    }
                }
            }
            case "下": {
                switch (op) {
                    case "Turn right": {
                        return "左";
                    }
                    case "Turn left": {
                        return "右";
                    }
                }
            }
            case "左": {
                switch (op) {
                    case "Turn right": {
                        return "上";
                    }
                    case "Turn left": {
                        return "下";
                    }
                }
            }
            case "右": {
                switch (op) {
                    case "Turn right": {
                        return "下";
                    }
                    case "Turn left": {
                        return "上";
                    }
                }
            }
        }
        return cur;
    }

    static Map<String, int[]> dirMap = new HashMap<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        List<Integer> collect = Arrays.stream(scanner.nextLine().split(" ")).map(Integer::parseInt).collect(Collectors.toList());
        int m = collect.get(0), n = collect.get(1);
        int r_x = 0, r_y = 0;
        char[][] board = new char[m][n];
        for (int i = 0; i < m; i++) {
            String s = scanner.nextLine();
            for (int j = 0; j < s.length(); j++) {
                board[i][j] = s.charAt(j);
                if (s.charAt(j) == 'R') {
                    r_x = i;
                    r_y = j;
                }
            }
        }
        String faceTo = "上";
        dirMap.put("上", new int[]{-1, 0});
        dirMap.put("下", new int[]{1, 0});
        dirMap.put("左", new int[]{0, -1});
        dirMap.put("右", new int[]{0, 1});
        int x = r_x, y = r_y;
        int nums = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < nums; i++) {
            String cmd = scanner.nextLine();
            faceTo = changeDirection(faceTo, cmd);
            if (cmd.contains("Forward")) {
                int step = Integer.parseInt(cmd.split(" ")[1]);
                int[] dir = dirMap.get(faceTo);
                for (int j = 0; j < step; j++) {
                    int dx = x + dir[0], dy = y + dir[1];
                    if (dx < 0 || dx > board.length - 1 || dy < 0 || dy > board[0].length - 1 || board[dx][dy] == 'O')
                        break;
                    x = dx;
                    y = dy;
//                    System.out.println("(" + x + "," + y + ")");
                }
            }
        }
        System.out.println((x - r_x) + " " + (y - r_y));
    }
}
